import MarkdownIt from 'markdown-it'
import hljs from 'highlight.js'

const mdi = new MarkdownIt({
  linkify: true,
  highlight: function (str, lang) {
    if (lang && hljs.getLanguage(lang)) {
      try {
        return '<pre class="hljs"><div class="code-block-header" style="display:none;"><span class="code-block-header__lang">' + lang + '</span><span class="code-block-header__copy">Copy Code</span></div><code>' +
          hljs.highlight(str, { language: lang, ignoreIllegals: true }).value +
          '</code></pre>';
      } catch (__) { }
    }

    return '<pre class="hljs"><div class="code-block-header" style="display:none;"><span class="code-block-header__lang">' + lang + '</span><span class="code-block-header__copy">Copy Code</span></div><code>' + mdi.utils.escapeHtml(str) + '</code></pre>';
  }
})

export default mdi